/**   
* @{#} GroupTableGenerator.java Create on 2013-6-26 上午10:01:14   
*   
* Copyright (c) 2012 by Baidu.   
*/
package objtable.core;

import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.CtNewMethod;
import javassist.NotFoundException;
import objtable.struct.DataType;
import objtable.struct.GroupRow;

/**   
* @author <a href="mailto:zhangbo07@baidu.com">zhangbo07</a>  
* @version 1.0   
*/

public class GroupTableGenerator extends TableGenerator {

	public GroupTableGenerator(String name) {
		super(name);
	}

	@Override
	protected void beforeGenClass(CtClass ctClass) {
		super.beforeGenClass(ctClass);
		//添加内部隐藏字段
		this.addFieldWithoutCheck(DataType.LIST_ROW, "t_sub", null);
	}

	@Override
	protected void afterGenClass(CtClass ctClass) {
		super.afterGenClass(ctClass);
		try {
			ctClass.addInterface(ctClass.getClassPool().getCtClass(
					GroupRow.class.getName()));
			//method public List<Row> getSubs();
			String tostr = "public java.util.List getSubs(){return this.t_sub;}";
			ctClass.addMethod(CtNewMethod.make(tostr, ctClass));
		} catch (CannotCompileException e) {
			e.printStackTrace();
		} catch (NotFoundException e) {
			e.printStackTrace();
		}
	}
}
